import { Component, ViewChild } from '@angular/core';
import { Banner } from 'src/app/data_type/common.type';
import { HomeService } from 'src/app/service/home/home.service';
import { PaginatorComponent } from '../paginator/paginator.component';


@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})
export class HomeComponent {

  searchQuery = '';  // <-- Add this line
  searchResults: any[] = [];

  pageIndex = 1;
  nzTotal = 51066444;
  nzPageSize = 10;

  constructor(private homeServe: HomeService) {
    console.log("HomeComponent constructor");
  }

  onPageChange($event: number) {
    this.search();
  }
  


  public search(): void {
    console.log(this.pageIndex);
    this.homeServe.searchHive(this.searchQuery, this.pageIndex, this.nzPageSize).subscribe(res => {
      console.log(res);
      this.searchResults = res.data.map((result: string) => {
        const parts = result.slice(1, -1).split(', ');
        return {
          id: parts[0],
          date: parts[1],
          host: parts[2],
          point: parts[3],
          value: parts[4],
          speed: parts[5]
        };
      });
      //给子组件 页码 总数  每页条数
    })
  }
}
